// pages/xianshangjiadingweitongji/xianshangjiadingweitongji.js
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    openid: '',
    jiami:  '',
    OPEN_ID:  '',
    session_key:  '',
    mealsList:  '',
    allNotNumber:'',
    allNumber:'',
    shuju:'',
  },

  back() {
    wx.navigateBack({
      delta: 1,
    })
  },







  chakan(){

    var that = this
    wx.request({
      url: app.globalData.interface+'/squareDance/API_5255_getAllCityDesc ',
      method: 'POST',
      data: {

        EMPLOYEE_ID: that.data.mealsList,
        OPEN_ID: that.data.openid, //用户OPEN_ID
        session_key: that.data.session_key,
        OPEN_UUID: that.data.jiami,

      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log('res', res);
        console.log('res', res.data.data);
        console.log('res', res.data.allNotNumber);
        if (res.data.result != 'success') {

          wx.showModal({
                  title: '温馨提示',
                  content: res.data.data,
                  success: function (res) {
                    if (res.confirm) {//这里是点击了确定以后
                    
                    } else {//这里是点击了取消以后
                      console.log('用户点击取消')
                    }
                  }
                })
   
        } else {

          that.setData({
            shuju:res.data.data,
            allNotNumber:res.data.allNotNumber,
            allNumber:res.data.allNumber,
          })

          console.log(111);
        }



      },
     
    })
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that = this
    that.setData({
      openid: app.globalData.openid,
      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      session_key: app.globalData.session_key,
      mealsList: app.globalData.mealsList,
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    var that = this

    if (that.data.jiami == '' || that.data.session_key == '') {

      wx.login({
        success: function (res) {
          console.log(res);
          if (res.code) { //wx.login获取code。
            console.log(res.code);
            //发起网络请求

            wx.request({
              url: app.globalData.interface+'/post/API_1062_appGetOpenid',
              // url: 'http://192.168.3.173:8081/post/API_1062_appGetOpenid',
              method: 'GET',
              //向后端发送的数据
              data: {
                code: res.code //将code发送到后台服务器。
              },
              header: {
                "Content-Type": "application/x-www-form-urlencoded" //POST方式是这个
              },
              success: res => {
                console.log(res);
                if (res.data.result != 'success') {
                  console.log(1);
                  // wx.showToast({
                  //   title: '请获取手机号',
                  //   duration: 1000
                  // })
                } else {
                  var openid = res.data.openid;
                  app.globalData.openid = openid;

                  console.log(res.data.openid);
                  that.setData({
                    openid: res.data.openid
                  })
                  // that.scanCod()

                  that.setData({
                    phone: app.globalData.phone,

                    jiami: app.globalData.jiami,
                    OPEN_ID: app.globalData.openid,
                    openid: app.globalData.openid,
                    session_key: app.globalData.session_key,
                  })
                  console.log(that.data.phone);
                  console.log(that.data.jiami);
                  console.log(that.data.openid);
                  console.log(that.data.session_key);

                  that.chakan()
                }

              }
            })
          } else {
            console.log('获取用户登录态失败！' + res.errMsg)
          }
        }
      });
    } else {

      console.log('成功');
      that.chakan()
    }

 

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})